﻿using System;
using System.IO;
using System.Windows.Media;

namespace Microsoft.Xna.Framework.Audio
{
#if !SILVERLIGHT3
	internal class MemoryStreamAudioSink : AudioSink
	{
		private MemoryStream mStream;

		public int GetBytes(byte[] buffer, int startIndex, int count)
		{
			byte[] tmpBuffer = mStream.GetBuffer();

			Array.Copy(tmpBuffer, startIndex, buffer, 0, count);

			return tmpBuffer.Length;
		}

		protected override void OnCaptureStarted()
		{
			mStream = new MemoryStream();
		}

		protected override void OnCaptureStopped()
		{
		}

		protected override void OnFormatChange(System.Windows.Media.AudioFormat audioFormat)
		{
			
		}

		protected override void OnSamples(long sampleTimeInHundredNanoseconds, long sampleDurationInHundredNanoseconds, byte[] sampleData)
		{
			mStream.Write(sampleData, 0, sampleData.Length);
		}
	}
#endif
}
